/*
 * sync_att.cpp
 *
 *  Created on: Sep 3, 2013
 *      Author: killerg
 */

#include "../server_deps.h"
#include "sync_att.h"



struct player {
    sync_att_t<cs::EPlAtt8Save> n8;
    sync_att_t<cs::EPlAtt4Save> n4;
    sync_att_t<cs::EPlAttDSave> d;

    int64_t att(cs::EPlAtt8Save att) { return n8.get(att); }
    int64_t att(cs::EPlAtt4Save att) { return n4.get(att); }
    int64_t att(cs::EPlAttDSave att) { return d.get(att); }

    void att(cs::EPlAtt8Save att, int64_t value) { n8.set(att, value); }
    void att(cs::EPlAtt4Save att, int32_t value) { n4.set(att, value); }
    void att(cs::EPlAttDSave att, double_t value) { d.set(att, value); }

    bool _init_syncatt(const Json::Value &json) {
        n8.init(json["n8"]);
        n4.init(json["n4"]);
        d.init(json["d"]);
        return true;
    }
    void _save_syncatt(Json::Value &json) {
        n8.save(json["n8"]);
        n4.save(json["n4"]);
        d.save(json["d"]);
    }

    void _fill_syncatt_init(cs::OPlayer* oplayer) {
        n8.fill_init(oplayer->add_att_init());
        n4.fill_init(oplayer->add_att_init());
        d.fill_init(oplayer->add_att_init());
    }
    void _fill_syncatt_sync(cs::SPlayerSync* splayersync) {
        n8.fill_sync(splayersync->add_att_sync());
        n4.fill_sync(splayersync->add_att_sync());
        d.fill_sync(splayersync->add_att_sync());
    }
};

bool test_sync_att() {

    Json::Value save;
    cs::OPlayer oplayer;
    cs::SPlayerSync splayersync;
    player create;
    create._save_syncatt(save);

    player p;
    p._init_syncatt(save);
    p._fill_syncatt_init(&oplayer);

    p.att(cs::Pl8s_GameMoney, 100);
    p.att(cs::Pl8s_Money, 2100);
    p._fill_syncatt_sync(&splayersync);


    return true;
}
